﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using Software_2Project.DB_Layer;
//using Software_2Project.DBstub_Layer;
using Software_2Project.Forms;
using System.Text.RegularExpressions;

namespace Software_2Project.Logic_Layer
{
    public class Logic_Login
    {
     
      

        public bool saveDB(Int32 acconum, Int32 password)
        {
            //=========validate Empty
            if (acconum.ToString() == null || password.ToString() == null)
                return false;
            //=========validate Number Only
            string patternValidate = "^[0-9]$";
            bool matchValidate   = Regex.IsMatch(acconum.ToString(), patternValidate);
            bool matchValidate_1 = Regex.IsMatch(password.ToString(), patternValidate);

            if (matchValidate && matchValidate_1)
                return false;            

            
            DB_LogForm dal = new DB_LogForm();
            DataTable dt = dal.retrieve(acconum,password);

            bool saved = false;
            foreach (DataRow dRow in dt.Rows)
            {
                //===============Validate Existance
                if (acconum == int.Parse(dRow["acconum"].ToString()) &&
                             password == int.Parse(dRow["password"].ToString()))
                {
                  //  accountNum = dRow["acconum"];
                    saved = true;
                }

            }
            return saved;

        }

     /*   public bool saveDB(int p1, int p2)
        {
            throw new NotImplementedException();
        }
       */
    }
}
